package com.zzyl.controller.manager;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.sun.xml.bind.v2.TODO;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DevicePropertyStatusVo;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import com.zzyl.vo.QueryThingModelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "Iot设备管理")
@RequestMapping("/iot")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    /**
     * 产品列表数据同步
     *
     * @return {@code ResponseResult<Void> }
     * @author YiSheep
     */
    @ApiOperation("产品列表数据同步")
    @PostMapping("/syncProductList")
    public ResponseResult<Void> syncProductList() {
        log.info("产品列表数据同步");
        deviceService.syncProductList();
        return ResponseResult.success();
    }

    /**
     * 查询所有产品列表
     *
     * @return {@code ResponseResult<List<ProductVo>> }
     * @author YiSheep
     */
    @ApiOperation("查询所有产品列表")
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct() {
        log.info("查询所有产品列表");
        List<ProductVo> productVoList = deviceService.allProduct();
        return ResponseResult.success(productVoList);
    }

    /**
     * 注册设备
     *
     * @param deviceDto 设备dto
     * @return {@code ResponseResult<Void> }
     * @author YiSheep
     */
    @ApiOperation("注册设备")
    @PostMapping("/RegisterDevice")
    public ResponseResult<Void> RegisterDevice(@RequestBody DeviceDto deviceDto) {
        log.info("注册设备:{}", deviceDto);
        deviceService.RegisterDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 分页查询设备
     *
     * @param dto 设备分页查询dto
     * @return {@code ResponseResult<PageBean<DeviceVo>> }
     * @author YiSheep
     */
    @ApiOperation("分页查询设备")
    @GetMapping("/pageQueryDevice")
    public ResponseResult<PageBean<DeviceVo>> pageQuery(DevicePageQueryDto dto) {
        log.info("分页查询设备:{}", dto);
        PageBean<DeviceVo> pageBean = deviceService.paegeQuery(dto);
        return ResponseResult.success(pageBean);
    }

    /**
     * 查询设备详情
     *
     * @param deviceDto 设备dto
     * @return {@code ResponseResult<DeviceVo> }
     * @author YiSheep
     */
    @ApiOperation("查询设备详情")
    @PostMapping("QueryDeviceDetail")
    public ResponseResult<DeviceVo> QueryDeviceDetail(@RequestBody DeviceDto deviceDto) {
        log.info("查询设备详情:{}", deviceDto);
        DeviceVo deviceVo = deviceService.QueryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    //============================================================== 课外作业


    /**
     * 查询指定设备的物模型运行状态
     *
     * @param request 查询设备属性状态请求
     * @return {@code ResponseResult<DevicePropertyStatusVo> }
     * @author YiSheep
     */
    @ApiOperation(value = "查询指定设备的物模型运行状态")
    @PostMapping("/QueryDevicePropertyStatus")
    public ResponseResult<DevicePropertyStatusVo> queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request) {
        DevicePropertyStatusVo devicePropertyStatusVo = deviceService.queryDevicePropertyStatus(request);
        return ResponseResult.success(devicePropertyStatusVo);
    }

    /**
     * 查询产品的物模型定义数据
     *
     * @param request 查询事物模型发布请求
     * @return {@code ResponseResult<QueryThingModelVo> }
     * @author YiSheep
     */
    @ApiOperation(value = "查询产品的物模型定义数据")
    @PostMapping("/QueryThingModelPublished")
    public ResponseResult<QueryThingModelVo> queryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request) {
        log.info("查询产品的物模型定义数据:{}", request);
        QueryThingModelVo queryThingModelVo = deviceService.queryThingModelPublished(request);
        return ResponseResult.success(queryThingModelVo);
    }

    /**
     * 修改设备备注名称
     *
     * @param deviceDto 设备dto
     * @return {@code ResponseResult<Void> }
     * @author YiSheep
     */
    @ApiOperation(value = "修改设备备注名称")
    @PostMapping("/UpdateDevice")
    public ResponseResult<Void> UpdateDevice(@RequestBody DeviceDto deviceDto) {
        log.info("修改设备备注名称:{}", deviceDto);
        deviceService.UpdateDevice(deviceDto);
        return ResponseResult.success();
    }

    /**
     * 删除设备
     *
     * @param deviceDto 设备dto
     * @return {@code ResponseResult<Void> }
     * @author YiSheep
     */
    @ApiOperation(value = "删除设备")
    @DeleteMapping("/DeleteDevice")
    public ResponseResult<Void> DeleteDevice(@RequestBody DeviceDto deviceDto) {
        log.info("删除设备:{}", deviceDto);
        deviceService.DeleteDevice(deviceDto);
        return ResponseResult.success();
    }
}
